#pragma once

#include "VisioCommon.h"
#include "Meshes.h"
#include "MeshInstances.h"
#include "CVApp.h"
#include <map>

typedef std::map<string,UINT> MenuMap;

enum FileMenuItems
{
	FILEMENU_OPEN_SCENE,
	FILEMENU_CREATE_SCENE,
};

enum ViewerMenuItems
{
	VIEWERMENU_BG_COLOR,
};

enum MouseMoveMode
{
	ORBIT,
	STAIONARY,
	TRANSLATE,
};

struct PickingAndScaleInfo
{
	UINT currSlot;
	float scalefactor[2];
	UINT cameraPicked[2];
	
};

class CCVGlutViewer
{
public:
	void OnKey(uchar key, int x, int y);
	void DisplayHelp();
	void MoveViewCam(uchar key);
	void LoadSceneFromFile(char* SceneName);
	void Run();
	void Render();
	void Test();
	CViewerCamera& GetViewCamera() {return m_ViewerCamera;}
	void ToggleCameraMove() {m_bMoveCam = !m_bMoveCam;}
	bool IsCamMoveAble() const {return m_bMoveCam;}
	void Init(int* argc, char** argv);
	void RunPhotoStich(char* SceneParams);
	void LoadImagesFromFile(FILE* pImgFile);
	void FileMenuHandler(int Value);
	void CreatePopMenu();
	void OpenSceneFile();
	void MouseClick(int button, int state, int x, int y);
	void SetGeometricParameters();
	void MouseMotion(int x, int y);
	void MouseWheel(int dir);
	void ChooseBGColor();
	void ViewerMenuHandler( int value );
	void CreateScene();
	bool GetSceneFileName(char* FileName);
	void OnUpKey(uchar key, int x, int y);
	void ScaleCam(int i, float delta);
	void RenderPicking();
	void CVGlInitPicking(UINT width, UINT height);
	void StartPicking(int x, int y);
private:

	// camera for the viewer not be confused with CCamera which are the objects
	CViewerCamera m_ViewerCamera;
	CCVApp m_CVApp;

	bool m_bMoveCam;
	bool m_bDrawFocusPoint;

	vector<CMesh*> m_Meshes;
	vector<CMeshInstance*> m_MeshInstances;
	
	ImagesVector m_Images;

	MenuMap m_MenuMap;

	MouseMoveMode m_MouseMode;

	Vector3f m_MeshCenter;

	COLORREF m_acrCustClr[16]; // array of custom colors 
	DWORD m_rgbCurrent;        // initial color selection
	bool m_bMenuUsed;

	GLuint m_fbo;
	GLuint m_pickingTexture;
	GLuint m_depthTexture;

	PickingAndScaleInfo m_PickInfo;
};